package com.example.gymmanagebackend.service.impl;

import com.example.gymmanagebackend.mapper.UserMapper;
import com.example.gymmanagebackend.pojo.User;
import com.example.gymmanagebackend.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public int addUser(User user) {
        return userMapper.addUser(user);
    }



    @Override
    public List<User> getAllUsers() {
        return userMapper.getAllUsers();
    }

    @Override
    public User findUserById(Integer id) {
        return userMapper.findUserById(id);
    }

    @Override
    public User findUserByUsername(String username) {
        return userMapper.findUserByUsername(username);
    }

    @Override
    public int deleteUserById(Integer id) {
        return userMapper.deleteUserById(id);
    }


    @Override
    public User login(String username, String password) {
        User user = userMapper.findUserByUsername(username);
        if (user != null && user.getPassword().equals(password)) {
            // 登录成功，返回用户对象
            return user;
        }
        return null; // 登录失败，返回null
    }
    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }
}